<?php
    class FeedbackMessageBox
    {
        const WARNING = 1;
        const ERROR = 2;

        /**
         * @var TemplateEngine
         */
        private $tmpl;
        private static $classNames = array(
            self::WARNING => 'warning',
            self::ERROR => 'error'
        );

        public function __construct()
        {
            $this->tmpl = Core::CreateTemplateEngine( PATH_TEMPLATES . "feedback_message/" );
            $this->tmpl->define( "feedback_message_box", "feedback_message_box.tpl" );
        }

        /**
         * @return FeedbackMessageBox
         */
        public static function GetInstance()
        {
            static $messageBox;
            if ( !isset( $messageBox ) )
            {
                $messageBox = new FeedbackMessageBox();
            }
            return $messageBox;
        }

        /**
         * @param int $boxType
         * @param string $message
         * @return string
         */
        public function Generate( $boxType, $message )
        {
            $tmpl = $this->tmpl;
            $tmpl->clearVars();

            $tmpl->set( 'CLASS', $this->GetClassName( $boxType ) );
            $tmpl->set( 'MESSAGE', $message );

            $tmpl->parse("content", "feedback_message_box");

            return $tmpl->getGenerated();
        }

        /**
         * Returns box class name by its type.
         * @param int $boxType
         * @return styring
         */
        private function GetClassName( $boxType )
        {
            $className = '';
            if ( array_key_exists( $boxType, self::$classNames ) )
            {
                $className = self::$classNames[$boxType];
            }
            return $className;
        }
    }
?>